import 'package:flutter/material.dart';
import 'package:flutter_div/div.dart';
import 'package:flutter_div/div_style.dart';

class DivCol extends StatelessWidget{

  /// Div纵轴布局
  const DivCol({
    super.key,
    required this.children,
    this.onTap,
    this.style,
    this.styles,
  });

  final void Function()? onTap;
  final DivStyle? style;
  final List<DivStyle>? styles;
  final List<Widget> children;

  @override
  Widget build(BuildContext context) {

    var mainAlign = style?.mainAlign;
    if(mainAlign == null && styles != null){
      for (DivStyle style in styles!.reversed) {
        if(style.mainAlign != null){
          mainAlign = style.mainAlign;
          break;
        }
      }
    }
    
    var crossAlign = style?.crossAlign;
    if(crossAlign == null && styles != null){
      for (DivStyle style in styles!.reversed) {
        if(style.crossAlign != null){
          crossAlign = style.crossAlign;
          break;
        }
      }
    }
    
    var mainSize = style?.mainSize;
    if(mainSize == null && styles != null){
      for (DivStyle style in styles!.reversed) {
        if(style.mainSize != null){
          mainSize = style.mainSize;
          break;
        }
      }
    }

    return Div(
      key: key,
      child: Column(
        mainAxisAlignment: mainAlign ?? MainAxisAlignment.start,
        crossAxisAlignment: crossAlign ?? CrossAxisAlignment.start,
        mainAxisSize: style?.mainSize ?? MainAxisSize.max,
        children: children,
      ),
      style: style,
      styles: styles,
      onTap: onTap,
    );
  }
}
